Skip to content

[dev-v5] Add Debounce - #2656

Merged
Vincent Baaij (vnbaaij) merged 7 commits into
dev-v5from
users/dvoituron/dev-v5/debounce
Sep 16, 2024
Merged

Vincent Baaij (vnbaaij) merged 7 commits into
dev-v5from
users/dvoituron/dev-v5/debounce

Conversation

@dvoituron

@dvoituron Denis Voituron (dvoituron) commented Sep 13, 2024 •

Copy link
Copy Markdown
Collaborator

[dev-v5] Add Debounce

The Debounce dispatcher delays the invocation of an action until a predetermined interval has elapsed since the last call.
This ensures that the action is only invoked once after the calls have stopped for the specified duration.

I created 2 classes:

  1. DebounceAction inspired from Microsoft.Toolkit.Uwp.UI.DispatcherQueueTimerExtensions and using System.Timers.Timer
  2. DeboundTask inspired from blog posts and using System.Task

The usage is identical, but I propose to use Debounce: DebounceTask. With the option of upgrading to the second class if problems are detected (to avoid losing this code).
And in some weeks, we could delete the second class to keep only one.

var debounce = new Debounce();

debounce.Run(50, async () =>
{
    actionCalled = true;
    await Task.CompletedTask;
});

@github-actions

github-actions Bot commented Sep 13, 2024 •

Copy link
Copy Markdown

✅ All tests passed successfully

Details on your Workflow / Core Tests page.

@github-actions

github-actions Bot commented Sep 13, 2024 •

Copy link
Copy Markdown

Summary - Unit Tests Code Coverage

Summary
Generated on: 09/16/2024 - 19:11:54
Coverage date: 09/16/2024 - 19:11:48
Parser: Cobertura
Assemblies: 1
Classes: 23
Files: 26
Line coverage: 99.2% (548 of 552)
Covered lines: 548
Uncovered lines: 4
Coverable lines: 552
Total lines: 2475
Branch coverage: 92% (393 of 427)
Covered branches: 393
Total branches: 427
Method coverage: Feature is only available for sponsors
Tag: 1481_10890451226

Coverage

Microsoft.FluentUI.AspNetCore.Components - 99.2%
Name Line Branch
Microsoft.FluentUI.AspNetCore.Components 99.2% 92%
Microsoft.FluentUI.AspNetCore.Components.Extensions.EnumExtensions 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentButton 100% 89.5%
Microsoft.FluentUI.AspNetCore.Components.FluentComponentBase 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentComponentElementBase 0%
Microsoft.FluentUI.AspNetCore.Components.FluentGrid 100% 91.6%
Microsoft.FluentUI.AspNetCore.Components.FluentGridItem 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentIcon`1 100% 95.8%
Microsoft.FluentUI.AspNetCore.Components.FluentLayout 100% 71.4%
Microsoft.FluentUI.AspNetCore.Components.FluentLayoutHamburger 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentLayoutItem 100% 89.2%
Microsoft.FluentUI.AspNetCore.Components.Icon 100% 91.1%
Microsoft.FluentUI.AspNetCore.Components.IconFromImage 100%
Microsoft.FluentUI.AspNetCore.Components.IconInfo 100%
Microsoft.FluentUI.AspNetCore.Components.Migration.AppearanceExtensions 100% 100%
Microsoft.FluentUI.AspNetCore.Components.Utilities.AddTag 100% 100%
Microsoft.FluentUI.AspNetCore.Components.Utilities.CssBuilder 100% 92.8%
Microsoft.FluentUI.AspNetCore.Components.Utilities.Identifier 100% 100%
Microsoft.FluentUI.AspNetCore.Components.Utilities.IdentifierContext 100% 75%
Microsoft.FluentUI.AspNetCore.Components.Utilities.InlineStyleBuilder 100% 92.8%
Microsoft.FluentUI.AspNetCore.Components.Utilities.InternalDebounce.Debounc
eAction
100% 83.3%
Microsoft.FluentUI.AspNetCore.Components.Utilities.InternalDebounce.Debounc
eTask
88.4% 75%
Microsoft.FluentUI.AspNetCore.Components.Utilities.InternalDebounce.Dispatc
herTimerExtensions
100% 85.7%
Microsoft.FluentUI.AspNetCore.Components.Utilities.StyleBuilder 100% 100%

@dvoituron

Copy link
Copy Markdown
Collaborator Author

Vincent Baaij (@vnbaaij) Which class do you prefer?

  1. DebounceAction inspired from Microsoft.Toolkit.Uwp.UI.DispatcherQueueTimerExtensions and using System.Timers.Timer
  2. DeboundTask inspired from blog posts and using System.Task

@vnbaaij

Copy link
Copy Markdown
Collaborator

I would be inclined to go with a System. Task based implementation. No real strong reason for that though 😁

@dvoituron

Copy link
Copy Markdown
Collaborator Author

Oh. I would have taken the Timer to follow UWP 😁

@dvoituron

Copy link
Copy Markdown
Collaborator Author

The usage of these 2 classes is identical. I propose to use Debounce: DebounceTask. With the option of upgrading to the second class if problems are detected (to avoid losing this code).
And in some weeks, we could delete the second class to keep only one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants